<?php
/**
 * Created by PhpStorm.
 * User: DELL
 * Date: 2018/7/11
 * Time: 16:59
 */
namespace app\admin;
use think\Controller;
use think\Session;

class BaseController extends Controller
{
    /**
     * 页码
     * @var string
     */
    public $page = '';

    /**
     * 每页显示多少条
     * @var string
     */
    public $size = '';

    /**
     * 数据的起始
     * @var int
     */
    public $start = 0;

    public function _initialize()
    {
        $username = Session::get('username');
        if(empty($username))
        {
            $this->error('您还没有登录','admin/login/index');
        }
    }

    /**
     * 获取 page start 和 size
     * @param $data
     */
    public function getPageAndSize($data)
    {
        $this->page = !empty($data['page'])?$data['page']:1;
        $this->size = !empty($data['size'])?$data['size']:config('paginate.list_rows');
        $this->start = ($this->page - 1) * $this->size;
    }
}